package com.code2roc.fastboot.system.setting.bizlogic;

import com.code2roc.fastboot.framework.cache.CacheUtil;
import com.code2roc.fastboot.model.BaseBootLogic;
import com.code2roc.fastboot.system.setting.model.SystemConfigDO;
import com.code2roc.fastboot.system.setting.service.ISystemConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class ConfigLogic extends BaseBootLogic {
    @Autowired
    private ISystemConfigService service;
    @Autowired
    private CacheUtil cacheUtil;

    public void insert(SystemConfigDO entity){
        service.insert(entity);
        cacheUtil.refreshCache("SystemConfig",entity.getConfig_name());
    }

    public void delete(String row_id){
        SystemConfigDO entity = service.selectOne(row_id);
        service.delete(row_id);
        cacheUtil.deleteCache("SystemConfig",entity.getConfig_name());
    }

    public void update(SystemConfigDO entity){
        service.update(entity);
        cacheUtil.refreshCache("SystemConfig",entity.getConfig_name());
    }

    public SystemConfigDO detail(String row_id){
        return service.selectOne(row_id);
    }

    public SystemConfigDO getConfigByName(String configName){
        return (SystemConfigDO)cacheUtil.getCache("SystemConfig",configName);
    }

    public String getConfigValueByName(String configName){
        return getConfigByName(configName).getConfig_value();
    }
}
